var global={};
global.dynaType={
    topic:1,
    comment:2,
    picture:3,
    question:4,
    notice:5,
    activity:6,
    join:7,
    create:8
};
global.isLoadingDynaList = false;//加载动态列表标记
global.dynaListPageNo=0;//动态列表当前页码
global.alert=function(txt,funcStr){
    var btnHtml = '<a class="cancel" href="javascript:void(0)" onclick="hidePop(\'alert\')">取消</a><a class="sure" href="javascript:$func">确定</a>';
    btnHtml = btnHtml.replace("$func",funcStr);
    showPop({
        str:"alert",
        txt:txt,
        btns:btnHtml
    });
}
global.hideAlert=function(){
    hidePop("alert");
}
global.error=function(txt){
    alertErrorTip(txt);
}
global.success=function(txt){
   alertSuccessTip(txt);
}
global.login=function(){
    showPop({
        str:"login"
    });
}
global.checkAdmin = function(){
    var me=this;
    if(!me.isLogin){
        me.login();
        return false;
    }
    if(me.isClubAdmin){
        return true;
    }else{
        me.error("您不是本车友会的管理员");
        return false;
    }
}
global.setReplyBtnStyle=function($input){
	 var val = $input.val();
	 var $btn = $input.parent(".replyData-inp").next().find(".reply-btn");
	 if(val==""){
		$btn.attr("class","reply-btn reply-btn-disable");
	 }else{
		$btn.attr("class","reply-btn");
	 }
}
global.initReply = function(){
    var me = this;
	if(me.isInitingReply){
		return;
	}
    $(".pinglun").live("click",function(){
        var dynaInfoId = $(this).attr("data-dynaInfoId");
        if($(this).attr("isLoadingReply")==="true"){
            return;
        }
        if($(this).attr("isShowReplyList")==="true"){
            $("div[data-replyList="+dynaInfoId+"] .replyData").remove();
             $(this).attr("isShowReplyList","false");
            return ;
        }
        $(this).attr("isLoadingReply","true");
        $(this).attr("isShowReplyList","true");
        var topicId= $(this).attr("reply-topicId"),forumId=$(this).attr("reply-forumId"),userId=$(this).attr("data-createBy");
        var dynaType = $(this).attr("data-dynaType");
        var oClubUrl = $(this).attr("data-oClubUrl");
        var activityId = $(this).attr("reply-activityId");
        if(!topicId){
            topicId=0;
        }
        if(!forumId){
            forumId=0;
        }
        if(!userId){
            userId=0;
        }
        if(!dynaType){
            dynaType=0;
        }
        if(!oClubUrl){
            oClubUrl="";
        }
        if(!activityId){
            activityId=0;
        }
        me.getReplyList(dynaInfoId,topicId,forumId,userId,dynaType,oClubUrl,activityId);
    });
	$("input[name=reply]").live("keyup",function(){
		 me.setReplyBtnStyle($(this));
	});
}
global.getReplyList =function(dynaInfoId,topicId,forumId,createBy,dynaType,oClubUrl,activityId){
    var me=this;
    $.get(me.root+"/dyna/getReplyListByDynaInfoId.do?dynaInfoId="+dynaInfoId, {}, function(d){
        if(d.code==0){
            var data = d.data;
            data.topicId=topicId;
            data.forumId=forumId;
            data.dynaInfoId=dynaInfoId;
            data.clubUrl=me.root+"/"+me.clubUrl+"/";
            data.clubName=me.clubName;
            data.BBSROOT=me.bbsRoot;
            data.UCROOT=me.ucRoot;
            data.clubId=me.clubId;
            data.userId=me.userId;
            data.createBy = createBy;
            data.dynaType = dynaType;
            data.oClubUrl = oClubUrl;
            data.activityId = activityId;
            for(var i=0,len=data.replyList.length;i<len;i++){
                data.replyList[i].content = me.transformBBSFaceToHTML(data.replyList[i].content);
            }
            $("div[data-replyList="+dynaInfoId+"]").append(template("template-dynaReplyList", data));
            $("#reply-"+dynaInfoId).attr("isLoadingReply","false");
        }
    }, "json");
}
global.addDyna = function(data){
	var me = this;
	data.clubUrl=me.clubUrl;
	data.ROOT = me.root;
	data.clubName=me.clubName;
	data.BBSROOT=me.bbsRoot;
	data.UCROOT=me.ucRoot;
	data.clubId=me.clubId;
	data.isClubAdmin=me.isClubAdmin;
	data.content = me.transformBBSFaceToHTML(data.content);
	$("#clubDynaList").prepend(template(data.templateId, data));	
	Lazy.create(globalLazy);
}
global.getDynaList = function(){
    var me = this;
    if(me.isLoadingDynaList){
        return;
    }
    me.isLoadingDynaList = true;
    var pageSize = 10;
    me.dynaListPageNo++;
    var t = new Date().getTime();
    $.get(me.root+"/dyna/getDynaListByClubId.do?needToViewUrl=1&clubId="+me.clubId+"&pageNo="+me.dynaListPageNo+"&_t="+t, {}, function(d){
        if(d.code==0){
            var list = d.data.list;
            if(list.length==0 || list.length<pageSize){
                $("#loadMoreDynaList").hide();
            }else{
                $("#loadMoreDynaList").show();
            }
            var idsStr = "";
            for(var i=0,len=list.length;i<len;i++){
                list[i].clubUrl=me.clubUrl;
				list[i].ROOT = me.root;
                list[i].clubName=me.clubName;
                list[i].BBSROOT=me.bbsRoot;
                list[i].UCROOT=me.ucRoot;
                list[i].clubId=me.clubId;
                list[i].isClubAdmin=me.isClubAdmin;
				list[i].content = me.transformBBSFaceToHTML(list[i].content);
				if(list[i].templateId == ""){
					console.log("not templateId : "+list[i].dynaInfoId);
					continue;
				}
				$("#clubDynaList").append(template(list[i].templateId, list[i]));
                //清除已置顶的按钮
                if($("#topClubDyna-"+list[i].dynaInfoId).length>0){
                    $("#setTopBtn-"+list[i].dynaInfoId).remove();
                }
                idsStr+=list[i].dynaInfoId+",";
            }
            if(global.isLogin){
                //设置已点赞的
                $.get(me.root+"/dyna/getPraiseList.do",{
                    dynaInfoIds:idsStr
                },function(rs){
                    if(rs.code==0){
                        var list = rs.data.list;
                        for(var i=0,len = list.length;i<len;i++){
                            $(".btn-zan[data-dynaInfoId='"+list[i].dynaInfoId+"']").addClass("btn-zan-active").attr("data-isClick","true");
                        }
                    }
                },"json");
                me.checkIsFocus();
            }
        }
		Lazy.create(globalLazy);
        me.isLoadingDynaList = false;
    }, "json");
}
global.getTopDynaList=function(){
    var me = this;
    var t = new Date().getTime();
    $.get(me.root+"/dyna/getTopList.do?clubId="+me.clubId+"&_t="+t, {}, function(d){
        if(d.code==0){
            var list = d.data.list;
            if(list.length==0){
                $("#topDynaList").html("");
            }else{
			    for(var i=0,len=list.length;i<len;i++){
                    list[i].clubId=me.clubId;
                    list[i].clubUrl=me.clubUrl;
                    list[i].BBSROOT=me.bbsRoot;
                    list[i].UCROOT = me.ucRoot;
                    list[i].ROOT=me.root;
                }
                $("#topDynaList").html(template("template-topDynaList",d.data));
            }
        }
    }, "json");
}

global.deleteClubDyna = function(dynaInfoId){
    var me = this;
    me.hideAlert();
    if(me.checkAdmin()){
        $.post(me.root+"/dyna/deleteDyna.do", {
            clubId:me.clubId,
            dynaInfoId:dynaInfoId
        }, function(rs){
            if(rs.code==0){
                $("#dynaInfoDiv-"+dynaInfoId).parent().remove();
                $("#topClubDyna-"+dynaInfoId).remove();
                me.success(rs.message);
            }else{
                me.error(rs.message);
            }
        }, "json");
    }
}

global.deleteClubDetailDyna = function(dynaInfoId){
    var me = this;
    me.hideAlert();
    var params = {
        "clubId":me.clubId,
        "dynaInfoId":dynaInfoId
    };
    if(me.isOwner){
        $.post(me.root+"/dyna/deleteDyna.do", {
            clubId:me.clubId,
            dynaInfoId:dynaInfoId
        }, function(rs){
            if(rs.code==0){
                $("#dynaInfoDiv-"+dynaInfoId).parent().remove();
                $("#topClubDyna-"+dynaInfoId).remove();
                me.success(rs.message);
                window.location.href=me.root+"/"+me.clubUrl+"/"; 
            }else{
                me.error(rs.message);
            }
        }, "json");
    }
}
global.setTop = function(dynaInfoId){
    var me = this;
    if(me.checkAdmin()){
        $.post(me.root+"/dyna/top.do", {
            clubId:me.clubId,
            dynaInfoId:dynaInfoId
        }, function(rs){
            if(rs.code==0){
                me.success(rs.message);
                me.getTopDynaList();
                $("#setTopBtn-"+dynaInfoId).remove();
            }else{
                me.error(rs.message);
            }
        }, "json");
    }
}
global.calcelTop = function(dynaInfoId){
    var me = this;
    me.hideAlert();
    if(me.checkAdmin()){
        $.post(me.root+"/dyna/cancelTop.do", {
            clubId:me.clubId,
            dynaInfoId:dynaInfoId
        }, function(rs){
            if(rs.code==0){
                me.success(rs.message);
                me.getTopDynaList();
                $("#dynaMenu-"+dynaInfoId).append('<a id="setTopBtn-'+dynaInfoId+'" href="javascript:global.setTop('+dynaInfoId+');">置顶</a>');
            }else{
                me.error(rs.message);
            }
        }, "json");
    }
}
global.initPraise = function(clickCall,unClickCall){
    var me = this;
    //点赞动画
    $(".btn-zan").live('click',function(){
        var $btn = $(this);
        var isPraise = 0;
        if(!me.isLogin){
            showPop({
                str:"login"
            });
            return false;
        }
        
        if($btn.attr("data-isClick")=="false"){
            isPraise = 1;

			var elem_s=$btn.children("s");
			var s=elem_s.html();
			elem_s.html(s*1+1);/*点赞数量+1*/ 
			$btn.addClass("btn-zan-active");       
			$btn.attr("data-isclick","true");
			var sp=$btn.position();
			var elem_i=$("#icon-zan");
			elem_i.attr("style","left:"+sp.left+"px;top:"+sp.top+"px");
			elem_i.animate({marginTop: -30, opacity: 0 },500);
			
            $(this).attr("data-isClick","true");
			if(clickCall){
				clickCall();
			}
        }else{
            $btn.attr("data-isClick","false");
            $btn.removeClass("btn-zan-active");
            var elem_s=$btn.children("s");
            var s=elem_s.html();
            elem_s.html(s*1-1);
			if(unClickCall){
				unClickCall();
			}
        }   
        $.post(me.root+"/dyna/doPraise.do", {
            createDate:$btn.parents(".dontai").attr("data-createDate"),
            dynaInfoId:$btn.parents(".dontai").attr("data-dynaInfoId"),
            isPraise:isPraise
        }, function(rs){
            }, "json");
    });
}
global.initAdminMenu = function(){
    var me = this;
    if(me.isClubAdmin){
        //置顶取消
        $("a.delete[data-isTop=true]").live("click",function(){
            var dynaInfoId = $(this).attr("data-dynaInfoId");
            var tip = "您确定要删除该置顶动态？";
            me.alert(tip, 'global.calcelTop('+dynaInfoId+')');
        });
        //动态删除
        $("a.delete[data-isTop=false]").live("click",function(){
            var type = $(this).attr("data-type");
            var dynaInfoId = $(this).attr("data-dynaInfoId");
            var tip = "动态删除后无法恢复，您确定要删除？";
            if(type==me.dynaType.picture){
                tip = '动态删除后无法恢复，但不会删除相册中的照片，您确定要删除？';
            }
            me.alert(tip, 'global.deleteClubDyna('+dynaInfoId+')');
        });
        //其他管理操作
        $(".banner .club-logo-r,.mainfocus,.club-main-info .des,.ul-txt-list li,.gonggao,.dontai-operate")
        .live('mouseenter',function(){
            $(this).addClass("hover");
        }).live('mouseleave',function(){
            $(this).removeClass("hover");
        });
    }
    //其他用户管理操作
    $(".dontai-operate")
    .live('mouseenter',function(){
        $(this).addClass("hover");
    }).live('mouseleave',function(){
        $(this).removeClass("hover");
    });
}
global.initOwnerMenu = function(){
    var me = this;
    if(me.isOwner){
        //动态删除
        $("a.delete[data-isTop=false]").live("click",function(){
            var type = $(this).attr("data-type");
            var dynaInfoId = $(this).attr("data-dynaInfoId");
            var tip = "动态删除后无法恢复，您确定要删除？";
            if(type==me.dynaType.picture){
                tip = '动态删除后无法恢复，但不会删除相册中的照片，您确定要删除？';
            }
            me.alert(tip, 'global.deleteClubDetailDyna('+dynaInfoId+')');
        });
        //其他管理操作
        $(".banner .club-logo-r,.mainfocus,.club-main-info .des,.ul-txt-list li,.gonggao,.dontai-operate")
        .live('mouseenter',function(){
            $(this).addClass("hover");
        }).live('mouseleave',function(){
            $(this).removeClass("hover");
        });
    }
}
global.initUnReadDyna = function(){
    var me = this;
    if(me.isMember){
        //获取当前用户未读消息
        $.ajax({
            type:"get",
            dataType : "jsonp",
            url:me.bipRoot+"/intf/sysnotice.jsp?act=find&siteId=2&typeIds="+me.clubDynaType+"&noTemplate=true&status=0",
            success:function(data){
                if(data.total>0){
                    var maxIndex = -1;
                    for(var i=0,len=data.resultList.length;i<len;i++){
                        var dynaInfoId = eval("("+data.resultList[i].content+")").dynaInfoId;
                        $("[id^=dynaInfoDiv-]").each(function(idx){
                            if("dynaInfoDiv-"+dynaInfoId==$(this).attr("id")){
                                if(idx>maxIndex){
                                    maxIndex = idx;
                                }
                            }
                        });
                    }
                    $("[id^=dynaInfoDiv-]").each(function(idx){
                        if(idx<=maxIndex){
                            $(this).addClass("dontai-new");
                        }
                    });
                }
            },
            error:function(){
               // console.log("find error");
            }
        });
        setTimeout(function () {
            $.ajax({
                type:"post",
                dataType : "json",
                url:me.root+"/intf/sysnotice.jsp?act=readAll&siteId=2&typeIds="+me.clubDynaType+"&groupType=7",
                success:function(data){
                    if(data.code==0){
                    }else{
                       // console.log(data.message);
                    }
                },
                error:function(){
                   // console.log("readAll error");
                }
            });
        }, 1000);
    }
}
global.smiliesUrlRoot = 'http://www1.pcauto.com.cn/autobbs/2013/images/emot/';
global.smilies_array=[];
global.postStatus = 0; // 回复状态 0:可以回复,1:回复中
global.smilies_array[0] = [];
global.smilies_array[0][1] = [['em2001','[抠鼻]','em1017.gif','32','32','50'],
    ['em2002','[鼓掌]','em1017.gif','32','32','50'],
    ['em2003','[可爱]','em1017.gif','32','32','50'],
    ['em2004','[偷笑]','em1017.gif','32','32','50'],
    ['em2005','[晕]','em1017.gif','32','32','50'],
    ['em2006','[调皮]','em1017.gif','32','32','50'],
    ['em2007','[微笑]','em1017.gif','32','32','50'],
    ['em2008','[流泪]','em1017.gif','32','32','50'],
    ['em2009','[大哭]','em1017.gif','32','32','50'],
    ['em2010','[憨笑]','em1017.gif','32','32','50'],
    ['em2011','[闭嘴]','em1017.gif','32','32','50'],
    ['em2012','[鄙视]','em1017.gif','32','32','50'],
    ['em2013','[可怜]','em1017.gif','32','32','50'],
    ['em2014','[无语]','em1017.gif','32','32','50'],
    ['em2015','[发呆]','em1017.gif','32','32','50'],
    ['em2016','[吐]','em1017.gif','32','32','50'],
    ['em2017','[流汗]','em1017.gif','32','32','50'],
    ['em2018','[翻白眼]','em1017.gif','32','32','50'],
    ['em2019','[发怒]','em1017.gif','32','32','50'],
    ['em2020','[尴尬]','em1017.gif','32','32','50'],
    ['em2021','[亲亲]','em1017.gif','32','32','50'],
    ['em2022','[擦汗]','em1017.gif','32','32','50'],
    ['em2023','[快哭了]','em1017.gif','32','32','50'],
    ['em2024','[色色]','em1017.gif','32','32','50'],
    ['em2025','[阴险]','em1017.gif','32','32','50'],
    ['em2026','[得意]','em1017.gif','32','32','50'],
    ['em2027','[睡觉]','em1017.gif','32','32','50'],
    ['em2028','[叹气]','em1017.gif','32','32','50'],
    ['em2029','[嘘]','em1017.gif','32','32','50'],
    ['em2030','[撇嘴]','em1017.gif','32','32','50'],
    ['em2031','[傲慢]','em1017.gif','32','32','50'],
    ['em2032','[饿]','em1017.gif','32','32','50'],
    ['em2033','[困]','em1017.gif','32','32','50'],
    ['em2034','[委屈]','em1017.gif','32','32','50'],
    ['em2035','[骷髅]','em1017.gif','32','32','50'],
    ['em2036','[敲头]','em1017.gif','32','32','50'],
    ['em2037','[惊讶]','em1017.gif','32','32','50'],
    ['em2038','[咒骂]','em1017.gif','32','32','50'],
    ['em2039','[抓狂]','em1017.gif','32','32','50'],
    ['em2040','[奋斗]','em1017.gif','32','32','50'],
    ['em2041','[哼哼]','em1017.gif','32','32','50'],
    ['em2042','[惊恐]','em1017.gif','32','32','50'],
    ['em2043','[衰]','em1017.gif','32','32','50'],
    ['em2044','[疑问]','em1017.gif','32','32','50'],
    ['em2045','[拜拜]','em1017.gif','32','32','50'],
    ['em2046','[强]','em1017.gif','32','32','50'],
    ['em2047','[弱爆]','em1017.gif','32','32','50'],
    ['em2048','[OK]','em1017.gif','32','32','50'],
    ['em2049','[握手]','em1017.gif','32','32','50'],
    ['em2050','[胜利]','em1017.gif','32','32','50'],
    ['em2051','[大便]','em1017.gif','32','32','50'],
    ['em2052','[心碎]','em1017.gif','32','32','50'],
    ['em2053','[玫瑰]','em1017.gif','32','32','50'],
    ['em2054','[小刀]','em1017.gif','32','32','50'],
    ['em1001','[顶]','em1017.gif','32','32','50'],
    ['em1002','[微笑]','em1017.gif','32','32','50'],
    ['em1003','[晕]','em1017.gif','32','32','50'],
    ['em1004','[汗]','em1017.gif','32','32','50'],
    ['em1005','[抱抱]','em1017.gif','32','32','50'],
    ['em1006','[狂笑]','em1017.gif','32','32','50'],
    ['em1007','[害羞]','em1017.gif','32','32','50'],
    ['em1008','[大哭]','em1017.gif','32','32','50'],
    ['em1009','[吐]','em1017.gif','32','32','50'],
    ['em1010','[问]','em1017.gif','32','32','50'],
    ['em1011','[闭嘴]','em1017.gif','32','32','50'],
    ['em1012','[鄙视]','em1017.gif','32','32','50'],
    ['em1013','[胜利]','em1017.gif','32','32','50'],
    ['em1014','[无语]','em1017.gif','32','32','50'],
    ['em1015','[美女]','em1017.gif','32','32','50'],
    ['em1016','[鬼脸]','em1017.gif','32','32','50'],
    ['em1017','[白眼]','em1017.gif','32','32','50'],
    ['em1018','[吻]','em1017.gif','32','32','50'],
    ['em1019','[凶]','em1017.gif','32','32','50'],
    ['em1020','[路过]','em1017.gif','32','32','50'],
    ['em1021','[口水]','em1017.gif','32','32','50'],
    ['em1022','[电话]','em1017.gif','32','32','50'],
    ['em1023','[委屈]','em1017.gif','32','32','50'],
    ['em1024','[握手]','em1017.gif','32','32','50'],
    ['em1025','[已阅]','em1017.gif','32','32','50'],
    ['em1026','[再见]','em1017.gif','32','32','50'],
    ['em1027','[抓狂]','em1017.gif','32','32','50'],
    ['em1028','[鼓掌]','em1017.gif','32','32','50'],
    ['em1029','[无聊]','em1017.gif','32','32','50'],
    ['em1030','[害怕]','em1017.gif','32','32','50'],
    ['em1031','[嘘]','em1017.gif','32','32','50'],
    ['em1032','[下台]','em1017.gif','32','32','50'],
    ['em1033','[偷看]','em1017.gif','32','32','50'],
    ['em1034','[加油]','em1017.gif','32','32','50'],
    ['em1035','[可怜]','em1017.gif','32','32','50'],
    ['em1036','[受伤]','em1017.gif','32','32','50'],
    ['em1037','[吃惊]','em1017.gif','32','32','50'],
    ['em1038','[帅气]','em1017.gif','32','32','50'],
    ['em1039','[睡觉]','em1017.gif','32','32','50'],
    ['em1040','[发火]','em1017.gif','32','32','50'],
    ['em1041','[酷]','em1017.gif','32','32','50'],
    ['em1042','[思考]','em1017.gif','32','32','50'],
    ['em1043','[得意]','em1017.gif','32','32','50'],
    ['em1044','[聪明]','em1017.gif','32','32','50'],
    ['em1045','[贪钱]','em1017.gif','32','32','50'],
    ['em1046','[痛苦]','em1017.gif','32','32','50'],
    ['em1047','[敬礼]','em1017.gif','32','32','50'],
    ['em1048','[牛气冲天]','em1017.gif','32','32','50'],
    ['em1049','[抠鼻子]','em1017.gif','32','32','50'],
    ['em1050','[膜拜]','em1017.gif','32','32','50'],
    ['em1051','[潜水]','em1017.gif','32','32','50'],
    ['em1052','[挨打]','em1017.gif','32','32','50'],
    ['em1053','[骷髅]','em1017.gif','32','32','50'],
    ['em1054','[抱拳]','em1017.gif','32','32','50']];
global.transformToBBSFace = function(str){
    var me = this;
    var oldStr = str;
    for(var i=0,len=me.smilies_array[0][1].length; i<len; i++) {
        var p = new RegExp(me.smilies_array[0][1][i][1].replace('[', '\\[').replace(']', '\\]'), 'gm');
        str = str.replace(p, '['+me.smilies_array[0][1][i][0]+']');
    }
    return str;
}
global.transformBBSFaceToHTML = function(str){
    var me = this;
    for(var i=me.smilies_array[0][1].length-1; i>=0; i--) {
        var p = new RegExp("\\["+me.smilies_array[0][1][i][0]+"\\]", 'gm');
        str = str.replace(p, "<img width=22 height=22 src="+me.smiliesUrlRoot+me.smilies_array[0][1][i][0]+".gif>");
    }
    return str;
}
global.transformToMessage = function(str){
	 var me = this;
	    for(var i=0,len=me.smilies_array[0][1].length; i<len; i++) {
	    	var p = new RegExp("\\["+me.smilies_array[0][1][i][0]+"\\]", 'gm');
	        str = str.replace(p, me.smilies_array[0][1][i][1]);
	    }
	    return str;
}

global.checkReplyContent = function($content){
    var me = this;
    if($content.val().replace(/(^\s*)|(\s*$)/g, "")==""){
        return false;
    }
    //TODO 长度判断
    return true;
}
global.replySuccessTip = function(){
	$("#Jsuccess-txt").html("回复成功");
    $("#Jsuccess").css({
        marginLeft:-$("#Jsuccess").width()/2
    }).show();
    setTimeout(function(){
        $('#Jsuccess').hide();
    },1500)
}
global.ajaxReplyToBBSTopic = function(node){
    var me = this;
    var data = {
        postToUserId:$(node).attr("data-postToUserId"),
        topicId:$(node).attr("data-topicId"),
        forumId:$(node).attr("data-forumId"),
        postToNickName:$(node).attr("data-postToNickName"),
		dynaInfoId:$(node).attr("data-dynaInfoId"),
		postToPostId:$(node).attr("data-postId")
    };
    var $content = $(node).parents(".replyData-tool").prev().find('input');
    var content = me.transformToBBSFace($content.val());
    if(!me.checkReplyContent($content)){
        return false;
    }
    if(!me.isLogin){
        showPop({
            str:"login"
        });
        return false;
    }
    if(me.postStatus==1){
        return false;
    }
    me.postStatus = 1;
    data.UCROOT=me.ucRoot;
    data.userId=me.userId;
    data.nickName=me.nickName;
    data.userAvatar=me.avatar50;
    data.content=content;
    data.createDate=$(node).parents(".dontai").attr("data-createDate");
    $.ajax({
        url:"/bbs/action/post/create.ajax",
        dataType:"json",
        data:{
            tid:data.topicId,
            message:data.content,
            fid:data.forumId,
			replyToId:data.postToPostId,
            sendMsg:true
        },
        type:"post",
        success: function(rs){
            me.postStatus = 0;
            if(rs.status==0){
                me.replySuccessTip();
				var ind = rs.message.indexOf("[/quote]");
				var msg = rs.message;
				if(ind>0){
					msg = rs.message.substr(ind+"[/quote]".length,rs.message.length);
				}
                var appContent = me.transformBBSFaceToHTML(msg.length>150?msg.substring(0,150)
                    +"...<a target='_blank' href='"+me.bbsRoot+"/post-"+rs.tid+"_"+rs.pid+".html'>详细</a>":msg);
                data.content=appContent;
                $(node).parents('.replyData').find(".replyData-list").prepend(template("template-dynaReplyListItem",data));
                $content.val("");//清空
				me.updateReplyCount(data.dynaInfoId);
            }else{
                me.error(rs.desc);
            }
        },
        error:function(xmlHttpRequest, textStatus, errorThrown){
            me.error("网络错误,请联系管理员");
            me.postStatus = 0;
        }
    });
}
global.showReplyBtn=function(node){
    var me = this;
    var $inner = $(node).parents("dd[data-reply-reply]").find(".replyData-inner");
    if($inner.length>0){
        $inner.remove();
    }else{
        var data={
            topicId:$(node).attr("data-topicId"),
            forumId:$(node).attr("data-forumId"),
            dynaInfoId:$(node).attr("data-dynaInfoId"),
            dynaReplyId:$(node).attr("data-dynaReplyId"),
            postToUserId:$(node).attr("data-postToUserId"),
            postToNickName:$(node).attr("data-postToNickName"),
			postId:$(node).attr("data-postId"),
            clubId:$(node).attr("data-clubId")
        };
        var html = template("template-dynaReplyReply",data);
        $(node).parents("dd[data-reply-reply]").append(html);
    }
}
global.updateReplyCount = function(dynaInfoId){
	$replyCount = $("#reply-"+dynaInfoId+" s");
	var replyCount = parseInt($replyCount.text())+1;
	$replyCount.text(replyCount);
	$("#replyCount s").text(replyCount);
	$("#dynaInfoDiv-"+dynaInfoId+" .replyData-list span[name='replyCount']").text(replyCount);//这个元素不一定有
}
global.ajaxReplyToDyna = function(node){
    var me = this;
    var data = {
        dynaInfoId:$(node).attr("data-dynaInfoId"),
        dynaReplyId:$(node).attr("data-dynaReplyId"),
        clubId:$(node).attr("data-clubId"),
        postToUserId:$(node).attr("data-postToUserId"),
        postToNickName:$(node).attr("data-postToNickName")
    };
    var $content = $(node).parents(".replyData-tool").prev().find('input');
    var content = me.transformToBBSFace($content.val());
    if(!me.checkReplyContent($content)){
        return false;
    }
    if(!me.isLogin){
        me.login();
        return false;
    }
    if(me.postStatus==1){
        return false;
    }
    me.postStatus = 1;
    data.UCROOT=me.ucRoot;
    data.userId=me.userId;
    data.nickName=me.nickName;
    data.userAvatar=me.avatar50;
    data.content=content;
    data.createDate=$(node).parents(".dontai").attr("data-createDate");
    $.ajax({
        url:"/dyna/replyDyna.do",
        data:{
            clubId:data.clubId,
            dynaInfoId:data.dynaInfoId,
            postToDynaReplyId:data.dynaReplyId,
            content:data.content,
            createDate:data.createDate
        },
        dataType:"json",
        type:"post",
        success:function(rs){
            if(rs.code==0){
                data.content = me.transformBBSFaceToHTML(rs.data.content);             
                $(node).parents('.replyData').find(".replyData-list").prepend(template("template-dynaReplyListItem",data));
                me.replySuccessTip();
                $content.val("");//清空
				me.updateReplyCount(data.dynaInfoId);
            }else{
                me.error(rs.message);
            }
            me.postStatus = 0;
        },
        error:function(xmlHttpRequest, textStatus, errorThrown){
            var message = "网络错误,请联系管理员";
            if(xmlHttpRequest.status==503){
                var json = eval("("+xmlHttpRequest.responseText+")");
                message = (json.message == ""?"网络错误,请联系管理员":json.message);
            }
            me.error(message);
            me.postStatus = 0;
        }
    });
}
// 表情展示
global.showface = function (e){
    $(e).parent().find(".replyData-face-pop").toggle();
}
// 表情输入到textarea
global.relayfaceInput = function(e){
    var facestr = $(e).find("img").attr("title");
    var faceinput = $(e).parents(".replyData-tool").prev().find("input");
    faceinput.val(faceinput.val()+facestr);
	global.setReplyBtnStyle(faceinput);
}
global.faceUrl1 = function(uid){
    if(typeof(uid)!="string" || uid=="0")
        return "";
    var picPath = "http://i6.3conline.com/images/upload/upc/face/";
    for(var i=0,s=uid.length;i<s;i++){
        var k = (i+2)<=s?(i+2):(i+1);
        picPath += uid.substring(i, k) +"/";
        i++;
    }
    return picPath+uid;
}
//获取头像地址,指定图片大小 20,50,70,100,120,150
global.faceSizeUrl1 = function(uid,sz){
	var me = this;
    var facesrc = me.faceUrl1(uid);
    if(facesrc.length==0)
        return "";
    if(typeof(sz)=="undefined")
        sz = "50x50";
    return facesrc + "_" + sz;
}
global.initSlide=function($target,$control,$img,callback){
    initSlide($target,$control,$img,callback);
}
global.initClubActivity=function(){
    var me = this;
    if($('#tab .contentdiv').length>0){
        me.initSlide($('#tab .contentdiv'),$('#tab .pagination .toc'),$('#tab .contentdiv img'));
    }
}
global.initClubFocusImg=function(){
    var me = this;
    if($('.mainfocus .slider_view li').length>=2){
        var m=0,n=0;
        var mainfocus = new Slide({
            target: $('.mainfocus .slider_txt li'),
            control:  false,
            effect: 'fade'
        });
        new Slide({
            control: $('.mainfocus .slider_thumb li.toc'),
            target:  $('.mainfocus .slider_view li'),
            effect: 'fade',
            autoPlay: true,
            stay: 5000,
            onchange: function(){
                mainfocus.playTo(this.curPage)
                var num = $('.mainfocus .slider_view li').length;
                var thumb = $('.mainfocus .slider_thumb img');
                var thumbImg = thumb.length;
                if(m<num){
                    var nli = this.target[this.curPage].getElementsByTagName("img")[0];
                    if(nli.getAttribute("#src")) {
                        nli.src = nli.getAttribute("#src");
                        nli.removeAttribute("#src");
                    }
                }
                m++;
                if(n<1){
                    for(var i = 0;i<thumbImg;i++){
                        if(thumb[i].getAttribute("#src")){
                            thumb[i].src = thumb[i].getAttribute("#src");
                            thumb[i].removeAttribute("#src");
                        }
                    }
                    n++;
                }
            }
        });
    }else{
        $('.mainfocus .slider_view img').attr('src',$('.mainfocus .slider_view img').attr('#src'));
    }
}
global.initShareUrl = function(){
   /*分享的弹窗*/
$("#btn-share").click(function(){
    $("#J-address").val("http://club.pcauto.com.cn/");
    window._bd_share_config.share.bdText="";
    window._bd_share_config.share.bdUrl="";
    showPop({str:"share"});
    copyText(1,'J-address-btn',$('#J-address').val(),'pop-share',function(){
            hidePop("share");
            showPop({
                str:"alert",
                txt:'复制成功，你可以使用ctrl+v粘贴到你想粘贴的地方了。',
                btns:'<a class="sure" href="javascript:void(0)" onclick="hidePop(\'alert\');">知道了</a>'
            });
        });      
});

$('.dtshare').live('click', function() {
    var url=$(this).attr("data-share-url");
    var txt=$(this).attr("data-share-txt");
	var pic=$(this).attr("data-share-pic");
    $("#J-address").val(url);
    window._bd_share_config.share.bdText=txt;
    window._bd_share_config.share.bdUrl=url;
	window._bd_share_config.share.bdPic=pic;
    showPop({str:"share"});
    copyText(1,'J-address-btn',$('#J-address').val(),'pop-share',function(){
            hidePop("share");
            showPop({
                str:"alert",
                txt:'复制成功，你可以使用ctrl+v粘贴到你想粘贴的地方了。',
                btns:'<a class="sure" href="javascript:void(0)" onclick="hidePop(\'alert\');">知道了</a>'
            });
        });   
	});
}
global.initFirstJoin=function(){
    var me = this;
    if(me.isLogin){
    	  if($.cookie("isFirstJoin") == "true"){
              delCookie("isFirstJoin");
              if(me.isClubAdmin){
		        	if(me.isLookedAdminGuide == 0){	        		
		        	 $("#JpopPoint1").hide();
		        	}
		        }else{
		        	if(me.isLookedMemberGuide == 0){
		        	  $("#JpopPoint2").hide();	       	     
		        	}
		        }
              showPop({str:"login-sucess",
              	     isClubAdmin:me.isClubAdmin,
              	     isLookedAdminGuide:me.isLookedAdminGuide,
              	     isLookedMemberGuide:me.isLookedMemberGuide,
              	     isMember:me.isMember
              	});          
          }else{
          	 	showGuide(me.isClubAdmin, me.isLookedAdminGuide, me.isLookedMemberGuide, me.isMember);
          }
    }
    //删除cookies 
    function delCookie(name) { 
        var exp = new Date(); 
        exp.setTime(exp.getTime() - 1000); 
        document.cookie= name + "=false;expires="+exp.toGMTString()+";domain=.pcauto.com.cn;path=/"; 
    } 
}

global.applySuccessByInvite=function(){
    var me = this;
    if($.cookie("isApplySuccess") == "true"){
        delCookie("isApplySuccess");
        showPop({str:"invite-success"});            
	}

    //删除cookies 
    function delCookie(name) { 
        var exp = new Date(); 
        exp.setTime(exp.getTime() - 1000); 
        document.cookie= name + "=false;expires="+exp.toGMTString()+";domain=.pcauto.com.cn;path=/"; 
    } 
}
global.visitPage=function(){
    var me = this;
    if(me.isLogin){//访客记录
        $.post(me.root+"/visitor/addUserVisitor.do",{
            clubId:me.clubId
        },function(){},"json");
    }
	//人气记录
	$.post(me.root+"/visitor/addPv.do",{
		clubId:me.clubId
	},function(){},"json");
}
global.initPvInfo=function(){
    var me = this;
    $.get(me.root+"/stat/getIndexPageView.do",{
        clubId:me.clubId,
		time:new Date().getTime()//需要实时，避免缓存
    },function(rs){
    	var vToday = rs.today;
    	if(vToday > 1000000) {
    		vToday = "1000000+";
    	} 
    	var vTotal = rs.total;
    	if(vTotal > 1000000) {
    		vTotal = "1000000+";
    	}
        $("#clubTodayPv").html(vToday+"<em></em>");
        $("#clubTotalPv").html(vTotal);
    },"json");
}
global.checkIsFocus=function(){
    var url = global.bipRoot+"/intf/focus.jsp?callback=?&accountId="+global.userId+"&act=isHisFocus";
    var flag = false;
    $(".dongtai-user-face[data-isChecked=false]").each(function(){
        url+="&friendIds="+$(this).attr("data-userId");
        flag = true;
    });
    if(flag){
        $.getJSON(url,{},function(data){
            $(".dongtai-user-face").each(function(){
                if(data[$(this).attr("data-userId")]==1){
                    //关注的人
                    var $a = $(this).find(".follow");
                    $a.addClass("unfollow").text("取消关注");
                    $a.attr("data-isFollow","true");
                }
                $(this).attr("data-isChecked","true");
            });
        });
    }
}
global.initFocus=function(){
    var me = this;
    if(me.isLogin){
        $(".dongtai-user-face").live('mouseenter',function(){
            if($(this).attr("data-userId")!=me.userId){
                $(this).addClass("hover");
            }else{
				
            }
        }).live('mouseleave',function(){
            if($(this).attr("data-userId")!=me.userId){
                $(this).removeClass("hover");
            }else{
				
            }
        });
    }
    $(".dongtai-user-face .follow[data-isFollow=true]").live("click",function(){
        if(!global.isLogin){
            global.login();
            return ;
        }
        var $this = $(this);
        var fid=$this.parent(".dongtai-user-face").attr("data-userId");
        $.post(global.root+"/intf/focus.jsp",{
            act:"delete",
            accountId:global.userId,
            friendId:fid
        },function(data) {
            eval("var result = " + data);
            if(result.code==0){
                $this.removeClass("unfollow").text("+关注");
                $this.attr("data-isFollow","false");   
            }else{
                global.error(result.message);
            }
        });
    });
    $(".dongtai-user-face .follow[data-isFollow=false]").live("click",function(){
        if(!global.isLogin){
            global.login();
            return ;
        }
        var $this = $(this);
        var fid=$this.parent(".dongtai-user-face").attr("data-userId");
        $.post(global.root+"/intf/focus.jsp",{
            act:"add",
            accountId:global.userId,
            friendId:fid
        },function(data) {
            eval("var result = " + data);
            if(result.code==0){
                $this.addClass("unfollow").text("取消关注");
                $this.attr("data-isFollow","true"); 
            }else{
                global.error(result.message);
            }
        });
    });
}
global.isCheckIn=false;//签到标识,防止重复点击
global.isOpenJoinDialog=false;
global.openJoinDialog=function(){
    var me = this;
    if(!me.isLogin){
        me.login();
        return;
    }
    if(me.isOpenJoinDialog){
        me.error("请不要重复点击");
        return;
    }
    me.isOpenJoinDialog=true;
    initJoinClubDialog(me);//活动终端页也有申请加入窗口
}
global.checkIn=function(){
    var me = this;
    if(!me.isLogin){
        me.login();
    }
    if(me.isCheckIn){
        me.error("请不要重复签到！");
        return;
    }
    me.isCheckIn = true;
    $.ajax({
        url:me.root+"/checkIn.do",
        dataType:"json",
        data:{
            clubId:me.clubId
        },
        type:"post",
        success:function(data) {
            if (data.status == 0) {
                var desc = eval("("+data.desc+")");
                me.checkInData.days++;
				me.checkInData.isCheckIn=true;
				$("#applyPart").html(template("template-applyPart",me.checkInData));
                me.success("签到成功，油值+"+desc.petrol+"L");//签到加分数
            } else {
                me.error(data.desc);
            }
        },
        error:function(xmlHttpRequest, textStatus, errorThrown){
            me.isCheckIn = false;
            var message = "网络错误,请联系管理员";
            if(xmlHttpRequest.status==503){
                var json = eval("("+xmlHttpRequest.responseText+")");
                message = (json.message == ""?"网络错误,请联系管理员":json.message);
            }
            me.error(message);
        }
    });
}
global.checkInData = {};
global.loadCheckInStat = function(){
    var me = this;
	me.checkInData.isCheckIn=false;
    if(!me.isLogin || !me.isMember){
		$("#applyPart").html(template("template-applyPart",{isCheckIn:false,isJoin:false}));
        return false;
    }else{
		$("#applyPart").html(template("template-applyPart",{isCheckIn:false,isJoin:true}));
    }
    //签到信息
    $.getJSON(me.root+"/checkIn/stat.do", {
        clubId:me.clubId,
        timestamp:new Date().getMilliseconds()
    }, function(data){
        if(!!data && data.status==0){
            var checkIn = new Function("return ("+data.desc+");")();
			me.checkInData.days=checkIn.continuous;
			me.checkInData.coins=checkIn.myCoin;
			me.checkInData.isJoin=true;
            if(checkIn.hasCheckedInToday){
                me.isCheckIn=true;
				me.checkInData.isCheckIn=true;
            }else{
                me.isCheckIn=false;
				me.checkInData.isCheckIn=false;
            }
			$("#applyPart").html(template("template-applyPart",me.checkInData));
        }
    });
    //实时读取排名
    $.getJSON(me.root+"/stat/getAllMemberRank.do",{
        clubId:me.clubId,
        userId:me.userId,
        timestamp:new Date().getMilliseconds()
    },function(data){
        if(data.rank>0){
			me.checkInData.rank=data.rank;
            $("#applyPart-myRank").text(data.rank);
        }
    });
}
global.initXz=function(){
	if($(".club-data-xz").attr("data-initJs")=="true"){
			$(".club-data-xz").hover(function(){
			$(this).addClass("on");
		},function(){
			$(this).removeClass("on");
		})
	}
}
global.initClubDataTips=function(){
	if($("#clubHasNoRank").length==0){
		$(".club-data-rank").hover(function(){
			$(".club-data-tips").show()
		},function(){
			$(".club-data-tips").hide();
		})	
	}
}
window.global=global;